package com.xie.smfs.client.screen;

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.util.Identifier;
import com.xie.smfs.util.TutorialManager;

import java.util.List;

public class TutorialScreen extends Screen {
    private static final Identifier BACKGROUND_TEXTURE = new Identifier("smfs", "textures/gui/tutorial_ground.png");

    private final TutorialManager tutorialManager;

    public TutorialScreen() {
        super(Text.translatable("screen.smfs.tutorial.title"));
        this.tutorialManager = TutorialManager.getInstance();
    }

    @Override
    protected void init() {
        super.init();
        // 移除了关闭按钮的添加代码
    }

    @Override
    public void render(DrawContext context, int mouseX, int mouseY, float delta) {
        context.drawTexture(BACKGROUND_TEXTURE, 0, 0, 0, 0, this.width, this.height, this.width, this.height);
        super.render(context, mouseX, mouseY, delta);

        // 渲染当前日的剧情文本
        String currentStory = tutorialManager.getCurrentStory();
        // 添加300像素宽度限制实现自动换行
        // 使用wrapLines实现文本换行
        List<OrderedText> wrappedText = this.textRenderer.wrapLines(Text.of(currentStory), 300);
        int y = 50;
        for (OrderedText line : wrappedText) {
            // 将文本颜色改为红色 (0xFF0000) 并增加行间距
            context.drawTextWithShadow(this.textRenderer, line, this.width / 2 - 150, y, 0xFF0000);
            y += this.textRenderer.fontHeight + 4; // 增加行距为原有的两倍
        }
    }

    @Override
    public boolean shouldCloseOnEsc() {
        return true;
    }

    @Override
    public void close() {
        this.client.setScreen(null);
    }
}